<?php

namespace App\Http\Controllers;

use App\Http\Requests\CreateSysCommentRequest;
use App\Http\Requests\UpdateSysCommentRequest;
use App\Models\Temp;
use App\Repositories\SysCommentRepository;
use App\Http\Controllers\AppBaseController;
use Illuminate\Http\Request;
use Flash;
use Prettus\Repository\Criteria\RequestCriteria;
use Response;

class SysCommentController extends AppBaseController
{
    /** @var  SysCommentRepository */
    private $sysCommentRepository;

    public function __construct(SysCommentRepository $sysCommentRepo)
    {
        $this->sysCommentRepository = $sysCommentRepo;
    }

    /**
     * Display a listing of the SysComment.
     *
     * @param Request $request
     * @return Response
     */
    public function index(Request $request)
    {
        $this->sysCommentRepository->pushCriteria(new RequestCriteria($request));
        $sysComments = $this->sysCommentRepository->all();

        return view('sys_comments.index')
            ->with('sysComments', $sysComments);
    }

    /**
     * Show the form for creating a new SysComment.
     *
     * @return Response
     */
    public function create()
    {
    	$temps = Temp::pluck('name', 'id');
        return view('sys_comments.create', compact('temps'));
    }

    /**
     * Store a newly created SysComment in storage.
     *
     * @param CreateSysCommentRequest $request
     *
     * @return Response
     */
    public function store(CreateSysCommentRequest $request)
    {
        $input = $request->all();

        $sysComment = $this->sysCommentRepository->create($input);

        Flash::success('Sys Comment saved successfully.');

        return redirect(route('sysComments.index'));
    }

    /**
     * Display the specified SysComment.
     *
     * @param  int $id
     *
     * @return Response
     */
    public function show($id)
    {
        $sysComment = $this->sysCommentRepository->findWithoutFail($id);

        if (empty($sysComment)) {
            Flash::error('Sys Comment not found');

            return redirect(route('sysComments.index'));
        }

        return view('sys_comments.show')->with('sysComment', $sysComment);
    }

    /**
     * Show the form for editing the specified SysComment.
     *
     * @param  int $id
     *
     * @return Response
     */
    public function edit($id)
    {
        $sysComment = $this->sysCommentRepository->findWithoutFail($id);

        if (empty($sysComment)) {
            Flash::error('Sys Comment not found');

            return redirect(route('sysComments.index'));
        }

        $temps = Temp::pluck('name', 'id');
        return view('sys_comments.edit')->with('sysComment', $sysComment)->with('temps', $temps);
    }

    /**
     * Update the specified SysComment in storage.
     *
     * @param  int              $id
     * @param UpdateSysCommentRequest $request
     *
     * @return Response
     */
    public function update($id, UpdateSysCommentRequest $request)
    {
        $sysComment = $this->sysCommentRepository->findWithoutFail($id);

        if (empty($sysComment)) {
            Flash::error('Sys Comment not found');

            return redirect(route('sysComments.index'));
        }

        $sysComment = $this->sysCommentRepository->update($request->all(), $id);

        Flash::success('Sys Comment updated successfully.');

        return redirect(route('sysComments.index'));
    }

    /**
     * Remove the specified SysComment from storage.
     *
     * @param  int $id
     *
     * @return Response
     */
    public function destroy($id)
    {
        $sysComment = $this->sysCommentRepository->findWithoutFail($id);

        if (empty($sysComment)) {
            Flash::error('Sys Comment not found');

            return redirect(route('sysComments.index'));
        }

        $this->sysCommentRepository->delete($id);

        Flash::success('Sys Comment deleted successfully.');

        return redirect(route('sysComments.index'));
    }
}
